<?php

namespace app\bll;

use support\Db;

class UserIntegralLog
{
    /**
     * 今日某个规则获取的积分
     *
     * @param integer $uid
     * @param integer $ruleid
     * @return integer
     */
    public function userTodayIntegral(int $uid, int $ruleid): int
    {
        return Db::table('frame_user_integral_log')
            ->where('uid', '=', $uid)
            ->where('ruleid', '=', $ruleid)
            ->where('addsub', '=', 1)
            ->where('addtime', '>=', strtotime(date('Y-m-d 00:00:00')))
            ->where('addtime', '<=', strtotime(date('Y-m-d 23:59:59')))
            ->sum('integral');
    }

    /**
     * 某个规则所有获取的积分
     *
     * @param integer $uid
     * @param integer $ruleid
     * @return integer
     */
    public function userIntegral(int $uid, int $ruleid): int
    {
        return Db::table('frame_user_integral_log')
            ->where('uid', '=', $uid)
            ->where('ruleid', '=', $ruleid)
            ->where('addsub', '=', 1)
            ->sum('integral');
    }
}
